package com.xianbeiying.app.ckgl.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lidroid.xutils.util.LogUtils;
import com.xianbeiying.app.ckgl.R;

import java.util.ArrayList;

/**
 * 实时状态数据适配
 */
public class ReTimeModeAdapterss extends BaseAdapter{
    private Context context;
    private ArrayList<String> endstr;
    private ArrayList<String>  runstr;
    private ArrayList<String>  nextstr;
    private int lengts;
    public ReTimeModeAdapterss(Context context, ArrayList<String>  endstr, ArrayList<String>   runstr, ArrayList<String>   nextstr) {
        this.context = context;
        this.endstr = endstr;
        this.runstr = runstr;
        this.nextstr = nextstr;
        if(endstr.size()>=runstr.size()&&endstr.size()>=nextstr.size()){
            lengts=endstr.size();
        }
        if(runstr.size()>=endstr.size()&&runstr.size()>=nextstr.size()){
            lengts=runstr.size();
        }
        if(nextstr.size()>=endstr.size()&&nextstr.size()>=runstr.size()){
            lengts=nextstr.size();
        }
        LogUtils.e(lengts+"---------");
    }

    @Override
    public int getCount() {
        return lengts+1;
    }

    @Override
    public Object getItem(int position) {
        return getItem(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_retime_mode, parent, false);
            holder = new ViewHolder();
            holder.rtv_end=(TextView) convertView.findViewById(R.id.rtv_end);
            holder.rtv_run=(TextView) convertView.findViewById(R.id.rtv_run);
            holder.rtv_next=(TextView) convertView.findViewById(R.id.rtv_next);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        if(position==0){
            holder.rtv_end.setText("已完成");
            holder.rtv_run.setText("正在进行");
            holder.rtv_next.setText("下一组");
        }else{
            if(endstr.size()!=0&&position<=endstr.size()){
                holder.rtv_end.setText(endstr.get(position-1));
            }
            else{
                holder.rtv_end.setText("");
            }
            if(runstr.size()!=0&&position<=runstr.size()){
                holder.rtv_run.setText(runstr.get(position-1));
            }else{
                holder.rtv_run.setText("");
            }
            if(nextstr.size()!=0&&position<=nextstr.size()){
                holder.rtv_next.setText(nextstr.get(position-1));
            }else{
                holder.rtv_next.setText("");
            }
//            if(position==endstr.length){
//                holder.rtv_end.setText(endstr[position-1]);
//            }else{
//                holder.rtv_end.setText("");
//            }
//            if(position==runstr.length){
//                holder.rtv_run.setText(runstr[position-1]);
//            }else{
//                holder.rtv_run.setText("");
//            }
//            if(position==nextstr.length){
//                holder.rtv_next.setText(nextstr[position-1]);
//            }else{
//                holder.rtv_next.setText("");
//            }
        }
        return convertView;
    }
    private class ViewHolder{
       TextView rtv_end;
       TextView rtv_run;
       TextView rtv_next;
    }
}
